package com.fr.report.script.function;

import com.fr.report.script.Function;
import com.fr.report.script.Function.Type;
import com.fr.report.script.NormalFunction;
import com.fr.report.script.Primitive;
import com.fr.report.script.core.FArray;

public class SLICEARRAY extends NormalFunction
{
  public Object run(Object[] paramArrayOfObject)
  {
    if ((paramArrayOfObject.length < 2) || (paramArrayOfObject.length > 3))
      return Primitive.ERROR_VALUE;
    Object localObject1 = paramArrayOfObject[0];
    if (!(localObject1 instanceof FArray))
      return Primitive.ERROR_VALUE;
    FArray localFArray = (FArray)localObject1;
    Object localObject2 = paramArrayOfObject[1];
    int i = 0;
    if (!(localObject2 instanceof Integer))
      return Primitive.ERROR_VALUE;
    i = Integer.parseInt(localObject2.toString());
    if (paramArrayOfObject.length == 2)
      return partArray(localFArray, i);
    Object localObject3 = paramArrayOfObject[2];
    int j = 0;
    if (!(localObject3 instanceof Integer))
      return Primitive.ERROR_VALUE;
    j = Integer.parseInt(localObject3.toString());
    return partArray(localFArray, i, j);
  }

  private FArray partArray(FArray paramFArray, int paramInt)
  {
    return partArray(paramFArray, paramInt, paramFArray.length());
  }

  private FArray partArray(FArray paramFArray, int paramInt1, int paramInt2)
  {
    FArray localFArray = new FArray();
    if (paramInt1 < 1)
      paramInt1 = 1;
    if (paramInt2 > paramFArray.length())
      paramInt2 = paramFArray.length();
    for (int i = paramInt1; i <= paramInt2; ++i)
      localFArray.add(paramFArray.elementAt(i - 1));
    return localFArray;
  }

  public Function.Type getType()
  {
    return Function.ARRAY;
  }

  public String getCN()
  {
    return "SLICEARRAY(array, start, end):返回数组从第start个到第end个元素(包括第end个元素)。\n示例：\nSLICEARRAY([3, 4, 4, 5, 1, 5, 7], 3, 6)返回[4, 5, 1, 5].\n当不使用end参数时，返回从start开始到数组结束之间的元素。\nSLICEARRAY([3, 4, 4, 5, 1, 5, 7], 3)返回[4, 5, 1, 5, 7].";
  }

  public String getEN()
  {
    return "";
  }
}